{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<style>

@font-face {

	font-family: 'FontAwesome';

	src: url('http://libs.baidu.com/fontawesome/4.1.0/fonts/fontawesome-webfont.eot?v=4.1.0');

	src: url('http://libs.baidu.com/fontawesome/4.1.0/fonts/fontawesome-webfont.eot?#iefix&v=4.1.0') format('embedded-opentype'), url('/css/fonts/fontawesome-webfont.woff?v=4.1.0') format('woff'), url('/css/fonts/fontawesome-webfont.ttf?v=4.1.0') format('truetype'), url('http://libs.baidu.com/fontawesome/4.1.0/fonts/fontawesome-webfont.svg?v=4.1.0#fontawesomeregular') format('svg');

	font-weight: normal;

	font-style: normal;

}

.icon-plus:before                 { content: "\f067"; }
.icon-minus:before                { content: "\f068"; }
[class^="icon-"]:before, [class*=" icon-"]:before {
  font-family: FontAwesome;
  font-weight: normal;
  font-style: normal;
  display: inline-block;
  text-decoration: inherit;
}
</style>
<script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>分数及介绍</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="questionListEdit" id="questionListEdit" method="post" action="{:url('ScoreEdit')}">
                        <input type="hidden" name="id" value="{$info['id']}">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">测评名称：</label>
                            <div class="input-group col-sm-4">
                                {$info['name']}
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">最高分：</label>
                            <div class="input-group col-sm-4">
                                <input id="score_max" type="text" class="form-control" name="score_max" value="{$info['score_max']}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        

						<div class="form-group options_group">
							<label class="col-sm-3 control-label"><span style="color:red;">&nbsp;</span>分数等级配置(由高到低配置)</label>
							<div> 
								<div class="input-group col-sm-10 field" style="display:none;float: right;"> 
									<input type="text" name="" placeholder="请输入等级名称" autocomplete="off" class="title" value="" >
									<input type="text" name="" placeholder="请输入分值" autocomplete="off" class="score" value="" >
									<textarea class="info" style="width:90%"></textarea>
									
									<span style="margin-right:5px;float: left;height: 33px;line-height: 33px;" class="icon-minus "></span>
								</div>
								<span style="margin-right:5px;float: left;height: 33px;line-height: 33px;" class="icon-plus "></span>
							</div>
							<div class="group2 input-group col-sm-8">
							{notempty name="options_list"}
							{volist name="options_list" id="vo"}
							<div class="input-group col-sm-10 field" style="float: right;">
								<input type="text" name="score_options[{$key}][title]" placeholder="请输入等级名称" autocomplete="off" class="title" value="{$vo['title']}" >
								<input type="text" name="score_options[{$key}][score]" placeholder="请输入分值" autocomplete="off" class="score" value="{$vo['score']}" >
								<textarea name="score_options[{$key}][info]" style="width:90%" id="myEditor{$key}">{$vo.info??''}</textarea>
								
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor{$key}");
                                </script>
								<span style="margin-right:5px;float: left;height: 33px;line-height: 33px;" class="icon-minus"></span>
							</div>
							{/volist}
							{/notempty}
							</div>
						</div>
                        
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<script type="text/javascript">

</script>
<script type="text/javascript">
		var j = "{$options_count}";
		$('.options_group').on('click','.icon-plus',function(){
			var html = $(this).parent().find('.field').clone();
			html.css('display','');
			html.find(".title").attr('name','score_options['+j+'][title]');
			html.find(".score").attr('name','score_options['+j+'][score]');
			html.find(".info").attr('name','score_options['+j+'][info]').attr('id','myEditor'+j);
			
			//setTimeout(() => {
			// new UE.ui.Editor().render("myEditor"+j);
			//}, 50); 
			const editorId = 'myEditor'+j;
			setTimeout(() => {
				if ($('#' + editorId).length > 0) {
					// 初始化UEditor
					const editor = UE.getEditor(editorId);
					
					// 监听编辑器就绪事件
					editor.ready(() => {
						console.log('编辑器已就绪:', editorId);
						$('#successMsg').text('编辑器创建成功: ' + editorId).show().fadeOut(3000);
					});
				} else {
					console.error('编辑器容器未找到:', editorId);
				}
			}, 50);
				
				
			$(this).closest('.form-group').children(".group2").append(html); 
			j++;	

		})   
		$('.group2').on('click','.icon-minus',function(){
			$(this).closest('.field').remove();
			//$(".group2 .field").each((h,item)=>{
			//	$(item).find(".title").attr('name','yuanxi['+h+'][title]');
			//	$(item).find(".major").attr('name','yuanxi['+h+'][major]');
			//});
			//j--;
		})
		
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val('/uploads/images/'+data._raw);
            $("#img_data").attr('src', '/uploads/images/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
            '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    //提交
    $(function(){
        $('#questionListEdit').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });



        function checkForm(){

            /*if( '' == $.trim($('#title').val())){
                layer.msg('请输入题目',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }*/
        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('ceping/index')}?no_ajax=1&page="+"{$page}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }
    });



    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>